package com.sjc.springbootdemo.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Classname AgeValidator
 * @Description
 * @Date 2020/4/23 17:11
 * @Created by SangJiacun
 */
public class AgeValidator implements ConstraintValidator<Age, Integer> {
    private Integer max;
    private Integer min;

    @Override
    public void initialize(Age age) {
        this.max = age.max();
        this.min = age.min();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return value < max && value > min;
    }
}
